/*
 * @Description: 
 * @Author: charles
 * @Date: 2021-09-23 17:01:50
 * @LastEditors: Please set LastEditors
<<<<<<< HEAD
 * @LastEditTime: 2021-10-22 11:40:28
=======
 * @LastEditTime: 2021-10-26 19:46:59
>>>>>>> 9375179 ('')
 */
import axios from 'axios'
import qs from 'qs'
import { Notify } from 'vant';

const instance = axios.create({
<<<<<<< HEAD
  baseURL: 'http://39.106.22.155:8002',
  timeout: 10000
=======
    //baseURL: 'http://121.199.29.84:8002',
    baseURL: 'http://39.106.22.155:8004',
    timeout: 10000
>>>>>>> 9375179 ('')
});
instance.interceptors.request.use((config) => {
    let token = localStorage.getItem('token')
    if (token) {
        config.headers.Authorization = token;
    }
    return config;
})
instance.interceptors.response.use(({ data: resp }) => {
    if (resp.status === 200) {
        return resp;
    }
    Notify({ type: "danger", message: resp.message });
    return Promise.reject(resp)
}, (error) => {
    Notify({ type: "danger", message: '交互异常' });
    return Promise.reject(error)
})


// url {id:1}
export function get(url, params) {
    return instance.get(url, { params })
}
export function post(url, data) {
    data = qs.stringify(data)
    return instance.post(url, data, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}
export function postJSON(url, data) {
    return instance.post(url, data)
}
export function del(url, params) {
    return instance.delete(url, { params })
}
export default instance;

// ...